package com.edu.exam.entity.grading.integration;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

/**
 * 集成任务详情实体类
 *
 * <p>所属模块：B-06 成绩管理模块</p>
 * <p>对应数据库表：integration_task_detail</p>
 *
 * <p>存储集成任务的详细处理记录</p>
 *
 * @author G-09 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
@Entity
@Data
@EqualsAndHashCode(callSuper = false)
public class IntegrationTaskDetail {

    @Id
    @Column(name = "detail_id", length = 64)
    private String detailId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "task_id", referencedColumnName = "task_id", nullable = false, foreignKey = @ForeignKey(name = "fk_integration_task_detail_task"))
    private IntegrationTask integrationTask;

    @Column(name = "record_id", length = 64, nullable = false)
    private String recordId;

    @Column(name = "record_sequence", nullable = false)
    private Integer recordSequence;

    @Column(name = "student_id", length = 32)
    private String studentId;

    @Column(name = "course_id", length = 32)
    private String courseId;

    @Column(name = "assessment_type", length = 32)
    private String assessmentType;

    @Column(name = "original_data", columnDefinition = "TEXT")
    private String originalData;

    @Column(name = "transformed_data", columnDefinition = "TEXT")
    private String transformedData;

    @Column(name = "process_status", length = 32, nullable = false)
    private String processStatus;

    @Column(name = "error_message", columnDefinition = "TEXT")
    private String errorMessage;

    @Column(name = "process_time")
    private LocalDateTime processTime;

    @CreationTimestamp
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @UpdateTimestamp
    @Column(name = "updated_time")
    private LocalDateTime updatedTime;

    /**
     * 获取关联的任务ID（为了便于查询）
     */
    @Transient
    public String getTaskId() {
        return integrationTask != null ? integrationTask.getTaskId() : null;
    }

}
